package chuishop.yiqimaicai.controller;

import chuishop.yiqimaicai.pojo.Addgoods_body;

import chuishop.yiqimaicai.pojo.Addgoods_header;
import chuishop.yiqimaicai.service.Addgoods_bodyService;
import chuishop.yiqimaicai.service.Addgoods_headerService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
//进货单明细
public class Addgoods_bodyController {
    @Autowired
    private Addgoods_bodyService addgoods_bodyService;
    //查询所有进货单头信息
    @RequestMapping("findAllAddgoods_body")
    @ResponseBody
    public PageInfo<Addgoods_body> findAllAddgoods_body(Integer pageNo,Integer pageSize) {
        if (pageNo == null) {
            pageNo = 1;
        }
        if (pageSize == null) {
            pageSize = 5;
        }

        //启动分页
        PageHelper.startPage(pageNo, pageSize);
        List<Addgoods_body> list = addgoods_bodyService.findAllAddgoods_body();
        PageInfo<Addgoods_body> pageInfo = new PageInfo<>(list);

        return pageInfo;
    }
    //根据输入查询进货单明细
    @RequestMapping("selectAddgoods_body")
    @ResponseBody
    public PageInfo<Addgoods_body> selectAddgoods_body(Integer pageNo, Integer pageSize, String selectInput){
        if(pageNo==null){
            pageNo=1;
        }

        if(pageSize==null){
            pageSize = 5;
        }

        //启动分页
        PageHelper.startPage(pageNo,pageSize);

        List<Addgoods_body> list = addgoods_bodyService.selectAddgoods_body(selectInput);
        PageInfo<Addgoods_body> pageInfo = new PageInfo<>(list);

        return pageInfo;
    }
    //添加供应商信息
    @RequestMapping("addAddgoods_body")
    @ResponseBody
    public Map<Object,Object> addAddgoods_body(@RequestBody Addgoods_body addgoods_body){

        Map<Object,Object> result=new HashMap<>();
        boolean flag=addgoods_bodyService.addAddgoods_body(addgoods_body);
        if(flag){
            result.put("status","200");
            result.put("msg","添加成功");
        }else
        {
            result.put("status","500");
            result.put("msg","添加失败");
        }
        return result;
    }
    //删除进货单头信息
    @RequestMapping("deleteAddgoods_body")
    @ResponseBody
    public Map<Object,Object> deleteAddgoods_body(String ids){

        String idstr[]=ids.split(",");
        Map<Object,Object> result=new HashMap<>();
        boolean flag= addgoods_bodyService.deleteAddgoods_body(idstr);
        if(flag){
            result.put("status","200");
            result.put("msg","删除成功");
        }else
        {
            result.put("status","500");
            result.put("msg","删除失败");
        }

        return result;
    }
    //更新进货单头信息
    @RequestMapping("updateAddgoods_body")
    @ResponseBody
    public Map<Object,Object> updateAddgoods_body(@RequestBody Addgoods_body addgoods_body){


        Map<Object,Object> result=new HashMap<>();
        boolean flag= addgoods_bodyService.updateAddgoods_body(addgoods_body);
        if(flag){
            result.put("status","200");
            result.put("msg","更新成功");
        }else
        {
            result.put("status","500");
            result.put("msg","更新失败");
        }

        return result;
    }
}
